package cn.iocoder.yudao.module.erp.controller.admin.dpitem.dpwestlistdn;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.erp.controller.admin.dpitem.dpwestlistdn.vo.DpWestListDnPageReqVO;
import cn.iocoder.yudao.module.erp.controller.admin.dpitem.dpwestlistdn.vo.DpWestListDnRespVO;
import cn.iocoder.yudao.module.erp.controller.admin.dpitem.dpwestlistdn.vo.DpWestListDnSaveReqVO;
import cn.iocoder.yudao.module.erp.dal.dataobject.dplist.DpWestListDnDO;
import cn.iocoder.yudao.module.erp.service.dpwest.DpWestListDnService;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;

import javax.validation.*;
import javax.servlet.http.*;
import java.io.IOException;
import java.util.List;

import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
import cn.iocoder.yudao.framework.apilog.core.annotation.ApiAccessLog;
import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.*;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;


@Tag(name = "管理后台 - 东宁西线清单")
@RestController
@RequestMapping("/erp/dp-west-list-dn")
@Validated
public class DpWestListDnController {

    @Resource
    private DpWestListDnService dpWestListDnService;

    @PostMapping("/create")
    @Operation(summary = "创建东宁西线清单")
    // @PreAuthorize("@ss.hasPermission('erp:dp-west-list-dn:create')")
    public CommonResult<Long> createDpWestListDn(@Valid @RequestBody DpWestListDnSaveReqVO createReqVO) {
        return success(dpWestListDnService.createDpWestListDn(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新东宁西线清单")
    // @PreAuthorize("@ss.hasPermission('erp:dp-west-list-dn:update')")
    public CommonResult<Boolean> updateDpWestListDn(@Valid @RequestBody DpWestListDnSaveReqVO updateReqVO) {
        dpWestListDnService.updateDpWestListDn(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除东宁西线清单")
    @Parameter(name = "id", description = "编号", required = true)
    // @PreAuthorize("@ss.hasPermission('erp:dp-west-list-dn:delete')")
    public CommonResult<Boolean> deleteDpWestListDn(@RequestParam("id") Long id) {
        dpWestListDnService.deleteDpWestListDn(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得东宁西线清单")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    // @PreAuthorize("@ss.hasPermission('erp:dp-west-list-dn:query')")
    public CommonResult<DpWestListDnRespVO> getDpWestListDn(@RequestParam("id") Long id) {
        DpWestListDnDO dpWestListDn = dpWestListDnService.getDpWestListDn(id);
        return success(BeanUtils.toBean(dpWestListDn, DpWestListDnRespVO.class));
    }

    @GetMapping("/page")
    @Operation(summary = "获得东宁西线清单分页")
    // @PreAuthorize("@ss.hasPermission('erp:dp-west-list-dn:query')")
    public CommonResult<PageResult<DpWestListDnRespVO>> getDpWestListDnPage(@Valid DpWestListDnPageReqVO pageReqVO) {
        PageResult<DpWestListDnDO> pageResult = dpWestListDnService.getDpWestListDnPage(pageReqVO);
        return success(BeanUtils.toBean(pageResult, DpWestListDnRespVO.class));
    }

    @GetMapping("/export-excel")
    @Operation(summary = "导出东宁西线清单 Excel")
    // @PreAuthorize("@ss.hasPermission('erp:dp-west-list-dn:export')")
    @ApiAccessLog(operateType = EXPORT)
    public void exportDpWestListDnExcel(@Valid DpWestListDnPageReqVO pageReqVO,
              HttpServletResponse response) throws IOException {
        pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
        List<DpWestListDnDO> list = dpWestListDnService.getDpWestListDnPage(pageReqVO).getList();
        // 导出 Excel
        ExcelUtils.write(response, "东宁西线清单.xls", "数据", DpWestListDnRespVO.class,
                        BeanUtils.toBean(list, DpWestListDnRespVO.class));
    }

}